{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## embeddings (adjacency)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "compute HH^T by [stacking H \\[j\\] 's vertically](https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.vstack.html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "compute embeddings (adjacency) for each node considering each node type (as before)\n",
    "'''\n",
    "\n",
    "from scipy.sparse import vstack as s_vstack\n",
    "\n",
    "embeddings = []\n",
    "for i in range(3):\n",
    "        '''\n",
    "        there cannot be relationships between nodes of the same type\n",
    "        e.g.: in a knowledge base, two subject nodes cannot be joined\n",
    "        '''\n",
    "        H_other = [H[j] for j in range(3) if j != i]\n",
    "        H_stack = s_vstack(H_other)\n",
    "        H_T = H_stack.T\n",
    "        \n",
    "        embeddings.append(H[i].dot(H_T))\n",
    "\n",
    "#embeddings = [H[i].dot(s_vstack([H[j] for j in range(3) if j != i]).T).astype('float') for i in range(3)]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
